package test.solution;

import java.util.*;

public class Main4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.next();
            char[] target = s.toCharArray();
            int n = scanner.nextInt();
            List<Set<Integer>> pathes = new ArrayList<Set<Integer>>();
            while (n-- > 0) {
                int x = scanner.nextInt();
                int y = scanner.nextInt();
                boolean contains = false;
                for (Set<Integer> set : pathes) {
                    if (set.contains(x)) {
                        if (!set.contains(y))
                            set.add(y);
                        contains = true;
                        break;
                    }
                    if (set.contains(y)) {
                        if (!set.contains(x))
                            set.add(x);
                        contains = true;
                        break;
                    }
                }
                if (!contains) {
                    TreeSet<Integer> set = new TreeSet<Integer>();
                    set.add(x);
                    set.add(y);
                    pathes.add(set);
                }
            }

            for (Set<Integer> set : pathes) {
                if (set.size() < 1) {
                    continue;
                }
                char[] cs = new char[set.size()];
                int i = 0;
                for (Integer x : set) {
                    cs[i] = target[x];
                    i++;
                }
                Arrays.sort(cs);
                i = 0;
                for (Integer x : set) {
                    target[x] = cs[i];
                    i++;
                }
            }
            System.out.println(new String(target));
        }//end scan
        scanner.close();
    }

    public static void foo(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.next();
            char[] target = s.toCharArray();
            int n = scanner.nextInt();
            List<int[]> pathes = new ArrayList<int[]>();
            while (n-- > 0) {
                int x = scanner.nextInt();
                int y = scanner.nextInt();
                pathes.add(new int[]{x, y});
            }
            boolean modified = true;
            while (modified) {
                modified = false;
                for (int[] path : pathes) {
                    if (target[path[0]] > target[path[1]]) {
                        char tmp = target[path[0]];
                        target[path[0]] = target[path[1]];
                        target[path[1]] = tmp;
                        modified = true;
                    }
                }//end for
            }//end while
            System.out.println(new String(target));
        }//end scan
        scanner.close();
    }
}